package judesart.app.client.ui.admin.project;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.google.gwt.user.client.ui.Image;

public class ImageDialog
{

    private final Dialog dialog;
    private final Image image;
    private final Button delete;
    private final Button save;
    private final TextArea area;

    public ImageDialog()
    {
        dialog = new Dialog();
        dialog.setSize(620, 600);
        dialog.setAutoHide(false);
        image = new Image();
        dialog.add(image);
        dialog.addText("Description:");
        area = new TextArea();
        area.setSize(800, 100);
        dialog.add(area);
        dialog.getButtonBar().removeAll();
        save = new Button();
        save.setText("Save");
        dialog.addButton(save);
        delete = new Button();
        delete.setText("Delete");
        dialog.addButton(delete);
        final Button cancel = new Button();
        cancel.setText("Cancel");
        cancel.addListener(Events.OnClick, new Listener<ButtonEvent>()
        {
            @Override
            public void handleEvent(ButtonEvent be)
            {
                dialog.hide();
            }
        });
        dialog.addButton(cancel);
    }

    public void show()
    {
        dialog.show();
    }

    public void hide()
    {
        dialog.hide();
    }

    public void setTextAreaValue(String value)
    {
        area.setValue(value);
    }

    public String getTextAreaValue()
    {
        return area.getValue();
    }

    public void setImageUrl(String url)
    {
        image.setUrl(url);
    }

    public void addSaveListener(Listener<ButtonEvent> saveClickListener)
    {
        save.addListener(Events.OnClick, saveClickListener);
    }

    public void addDeleteListener(Listener<ButtonEvent> deleteClickListener)
    {
        delete.addListener(Events.OnClick, deleteClickListener);
    }
}
